package com.sun.btrace.comm;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

public class ConfCommand extends Command {
	/*
	 * set >0, configure the agent set <0, get the configure from agent
	 */
	public enum OPERATOR{SETPASSWORD, LOGIN, RESETPASSWORD, GETCONF,SETCONF, REFINECLASS, REFINECLASS2FILE, ATTACHJAR};

	private OPERATOR  operator ;

	

	ConfBody body;
	ClassPairBody []cbody ;
	
	public ConfCommand() {
		super(CONF);
		operator = null ;
		body = new ConfBody();
	}

	

	@Override
	protected void read(ObjectInput in) throws IOException,
			ClassNotFoundException {
		// TODO Auto-generated method stub
		operator =  OPERATOR.values()[in.readInt()];
		body.read(in);
		if( operator == OPERATOR.REFINECLASS||operator == OPERATOR.REFINECLASS2FILE || operator == OPERATOR.ATTACHJAR){
			int len= in.readInt();
			cbody = new ClassPairBody[len] ;
			for( int i=0; i< len; ++i){
				cbody[i] = new ClassPairBody(null,null) ;
				cbody[i].read(in);	
			}
		}
	}

	@Override
	protected void write(ObjectOutput out) throws IOException {
		// TODO Auto-generated method stub
		out.writeInt(operator.ordinal());
		body.write(out);
		if( operator == OPERATOR.REFINECLASS||operator == OPERATOR.REFINECLASS2FILE || operator == OPERATOR.ATTACHJAR){
			out.writeInt(cbody.length) ;
			for( ClassPairBody c: cbody){
				c.write(out) ;
			}
		}
	}


	public ConfBody getBody() {
		return body;
	}

	public void setBody(ConfBody body) {
		this.body = body;
	}
	public OPERATOR getOperator() {
		return operator;
	}

	public void setOperator(OPERATOR operator) {
		this.operator = operator;
	}
	public ClassPairBody[] getCbody() {
		return cbody;
	}

	public void setClassBody(ClassPairBody[] cbody) {
		this.cbody = cbody;
	}
}
